package com.aiden.cashbook.charge

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentPagerAdapter
import com.aiden.cashbook.R
import com.aiden.cashbook.base.BaseActivity
import com.aiden.cashbook.charge.dagger.DaggerChargeFragmentComponent
import com.aiden.cashbook.extension.string
import kotlinx.android.synthetic.main.activity_charge.*
import javax.inject.Inject

class ChargeActivity: BaseActivity() {

    @Inject
    lateinit var chargeIncomeFragment: ChargeFragment

    @Inject
    lateinit var chargeExpenseFragment: ChargeFragment
    override fun onCreate() {
        hideToolbar()
        setContentView(R.layout.activity_charge)
        DaggerChargeFragmentComponent.builder().build().inject(this)
        val bundle = Bundle()
        bundle.putString("type", "expense")
        chargeExpenseFragment.arguments = bundle
        val bundle2 = Bundle()
        bundle2.putString("type", "income")
        chargeIncomeFragment.arguments = bundle2
        ib_back.setOnClickListener { finish() }
    }

    override fun initData() {
        viewpager_charge.adapter = object : FragmentPagerAdapter(supportFragmentManager) {
            override fun getItem(position: Int): Fragment {
                return when(position) {
                    0 -> chargeExpenseFragment
                    1 -> chargeIncomeFragment
                    else -> chargeExpenseFragment
                }
            }

            override fun getCount(): Int {
                return 2
            }

            override fun getPageTitle(position: Int): CharSequence? {
                if(position == 0) {
                    return string(R.string.expense)
                } else {
                    return string(R.string.income)
                }
            }
        }
        tab_charge.setupWithViewPager(viewpager_charge)
    }
}